package com.wesley.singleton;


/**
 * <h1>饿汗模式（静态块）</h1>
 * <p>
 *   创建一个内部私有变量 ，通过静态方法块
 * </p>
 */
public class SingletonTest2 {

    // 测试方法
    public static void main(String[] args) {
        Singleton2 test1 = Singleton2.getInstance();
        Singleton2 test2 = Singleton2.getInstance();
        System.out.println(test1 == test2);
    }
}

class Singleton2 {
    private final static Singleton2 SINGLETON;
    static {
        SINGLETON = new Singleton2();
    }
    // 利用构造函数进行一个初始化
    private Singleton2() {}
    public static Singleton2 getInstance() {
        return SINGLETON;
    }
}
